package com.litq.education.serviceImpl;



import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.litq.education.bean.CustomerTable;
import com.litq.education.bean.VipTable;
import com.litq.education.mapper.CustomerMapper;
import com.litq.education.mapper.VipMapper;
import com.litq.education.service.VipService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cglib.beans.BeanMap;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * VipServiceImpl
 *
 * 实现类
 *
 * @author litq
 * @version v1.0
 * @since 2019/2/10 1:31
 */



@Service("VipService")
public class VipServiceImpl  implements VipService {
    private static final Logger logger = LoggerFactory.getLogger(VipServiceImpl.class);
    @Resource

    private VipMapper VipMapper;

    @Override
    public Page<Map<String, Object>> selectListPage(int current, int number) {

        Page<Map<String, Object>> page = new Page<Map<String, Object>>(current, number);
        // 返回分页结果 1为id
        logger.info("----------------------------------查询结果打印" + page.setRecords(this.VipMapper.dyGetUserList(page, 1)));
        return page.setRecords(this.VipMapper.dyGetUserList(page, 1));
    }

    /**
     * 查询信息总数
     *
     * @return 返回总数
     * @author Litq
     * @version 1.0
     */
    @Override
    public int selectListcount() {

        logger.info("----------------------------------开始进行查询逻辑处理");
        return VipMapper.count();

    }

    /**
     * 查询客户信息
     *
     * @param username 姓名
     * @return 返回list
     * @author Litq
     * @version 1.0
     */
    @Override
    public List selectListPageByUserName(String username) {
        logger.info("----------------------------------开始进行查询逻辑处理");

        logger.info("----------------------------------查询结果打印" + (List) VipMapper.dyGetUserListByUsername(username));
        return (List) VipMapper.dyGetUserListByUsername(username);
    }

    @Override
    public int deleteById(int id) {

        logger.info("----------------------------------开始进行删除逻辑处理");
        logger.info("----------------------------------打印要删除的id号码:" + id);
        int sign = VipMapper.deleteById(id);
        return sign;
    }


    /**
     * 根据id查询客户
     *
     * @param id 客户id
     * @return list
     * @author Litq
     * @version 1.0
     */
    @Override
    public Map findCustomerById(int id) {
        logger.info("----------------------------------开始进行查询逻辑处理");
        VipTable ct = VipMapper.selectById(id);
        Map<String, Object> map = new HashMap();
        if (ct != null) {
            BeanMap beanMap = BeanMap.create(ct);
            for (Object key : beanMap.keySet()) {
                map.put(key + "", beanMap.get(key));
            }
        }
        logger.info("----------------------------------打印查询结果" + map);
        return map;
    }

    /**
     * 修改客户信息
     *
     * @param reqMap 客户信息
     * @return list
     * @author Litq
     * @version 1.0
     */
    @Override
    public int updateCustomerById(Map reqMap) {
        logger.info("----------------------------------开始进行修改逻辑处理");
        VipTable ct = new VipTable();

        int sign = 0;


        ct.setId(Integer.parseInt(reqMap.get("id").toString()));
        ct.setVipSex(reqMap.get("vipSex").toString());
        ct.setVipNum(reqMap.get("vipNum").toString());
        ct.setVipGuitar(reqMap.get("vipGuitar").toString());
        ct.setVipCard(reqMap.get("vipCard").toString());
        ct.setVipPhone(reqMap.get("vipPhone").toString());
        ct.setVipSex(reqMap.get("vipSex").toString());
        ct.setVipName(reqMap.get("vipName").toString());
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date1 = sdf.format(date);

        ct.setVipCreatetime(date1);

        sign = VipMapper.updateById(ct);
        logger.info("----------------------------------打印处理结果" + sign);
        return sign;
    }

    /**
     * 插入一条客户信息
     *
     * @param reqMap 客户信息
     * @return list
     * @author Litq
     * @version 1.0
     * @return 999 人数已经满员  000 人数相等  1插入成功
     */
    @Override
    public int insertCustomer(Map reqMap) {
        logger.info("----------------------------------开始进行插入逻辑处理");
        logger.info("----------------------------------是否存在参数"+reqMap);
        int sign = 0;
        VipTable ct = new VipTable();
        ct.setId(Integer.parseInt(reqMap.get("id").toString()));
        ct.setVipSex(reqMap.get("vipSex").toString());
        ct.setVipNum(reqMap.get("vipNum").toString());
        ct.setVipGuitar(reqMap.get("vipGuitar").toString());
        ct.setVipCard(reqMap.get("vipCard").toString());
        ct.setVipPhone(reqMap.get("vipPhone").toString());
        ct.setVipSex(reqMap.get("vipSex").toString());
        ct.setVipName(reqMap.get("vipName").toString());
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String date1 = sdf.format(date);

        ct.setVipCreatetime(date1);
        sign= VipMapper.insert(ct);
        return sign;
    }


}
